<template>
    <view>
        <!-- pages/user/collect/index.wxml -->
        <!-- 头部 -->
        <navber id="head-navber" :navbarData="navbarData"></navber>

        <goods :goodsList="dataList"></goods>

        <!-- 无数据 -->
        <view class="not-data" v-if="dataList.length == 0">
            <image :src="imgUrl + '/imgs/user/collect/not_data.png'"></image>
        </view>
    </view>
</template>

<script>
import navber from '@/components/navber/index';
import goods from '@/components/goods/index';
// pages/user/collect/index.js
const Config = require('../../../config/index.js');

const Api = require('../../../api/index.js');

export default {
    components: {
        navber,
        goods
    },
    data() {
        return {
            navbarData: {
                title: '我的收藏' //顶部标题
            },
            //导航栏
            imgUrl: Config.imgUrl,
            //图片url
            dataList: [],
            pagenow: 1
        };
    },
    onReachBottom: function (e) {
        //滚动底部
        var page = this.pagenow + 1;
        this.setData({
            pagenow: page
        });
        this.getData();
    },
    onShow() {
        this.setData({
            dataList: []
        });
        this.getData();
    },
    onPullDownRefresh(e) {
        this.getData();
        uni.stopPullDownRefresh();
    },
    methods: {
        getData() {
            //获取数据
            var json = {
                type: 1,
                //收藏
                pagenow: this.pagenow
            };
            Api.userCollectOrUp(json).then((res) => {
                if (res.data.length > 0) {
                    var data = this.dataList;
                    data = data.concat(res.data);
                    this.setData({
                        dataList: data
                    });
                } else {
                    uni.showToast({
                        title: '暂无数据',
                        icon: 'none',
                        duration: 2000
                    });
                } // wx.stopPullDownRefresh();
            });
        }
    }
};
</script>
<style>
@import './index.css';
</style>
